package client.gui;

import java.awt.Button;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 * The Class IncorrectNameGui
 *  - used when the client enters a name that is already used.
 */
public class IncorrectNameGui extends JPanel{
	
	/** The universal version identifier. */
	private static final long serialVersionUID = 9009761098194532852L;
	
	/** The JFrame on which the panel is added. */
	JFrame frame;
	
	/**
	 * Instantiates a new incorrect name gui.
	 */
	public IncorrectNameGui(){
		run();
	}
	
	/**
	 * Run
	 * - Creates the gui.
	 */
	public void run(){
		frame = new JFrame("Name error");
		frame.setVisible(true);
		JLabel error = new JLabel("Name already taken.", JLabel.CENTER);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setLayout(new GridLayout(2,1));
		frame.setSize(200, 75);
		error.setVisible(true);
		Button ok = new Button(("OK"));
		ok.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseReleased(MouseEvent e) {
				frame.dispose();
			}
		});
		this.add(error);
		this.add(ok);
		frame.add(this);
	}
}
